  <div class="row">
    <div class="span12">
      <div class='panel'>
      <h2 style="margin-bottom:20px;">Team: <?php echo $user->username;?> </h2>
      <?php if(!stage_started(0)) { ?>
      <div class='buttons' style="margin-bottom: 20px;"><?php echo anchor('selection/edit', '<i class="icon-edit icon-white"></i> '.lang('edit_selection'), 'class="btn btn-primary"'); ?></div>
      <p><?php echo lang('selection_intro_pre'); ?></p>
      <?php
      }
      else
      {
      ?>
      <p><?php echo lang('selection_intro_post');?></p>
      <?php  
      } ?>
        <table class="table table-condensed">
          <thead>
            <tr>
              <th colspan='2' rowspan='2'><?php echo lang('number');?></th>
              <th rowspan='2'><?php echo lang('name');?></th>
              <th rowspan='2'><?php echo lang('rider_type');?></th>
              <th rowspan='2'><?php echo lang('team');?></th>
              <th colspan='4' class='centertext'><?php echo lang('points');?></th>
            </tr>
            <tr>
              
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('stage_results');?>"><img src="<?php echo base_url();?>assets/images/jersey_stage.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('overall_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_yellow.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('points_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_green.gif" /></a></th>
              <th class='centertext'><a href="#" rel="tooltip" title="<?php echo lang('mountain_standing');?>"><img src="<?php echo base_url();?>assets/images/jersey_mountain.gif" /></a></th>
            </tr>
          </thead>
          <tbody>
        <?php
          $i=0;
          $total_stage_points = 0;
          $total_yellow_points = 0;
          $total_green_points = 0;
          $total_mountain_points = 0;
          
          foreach ($selection as $rider)
        {
          
        ?>
          
        <?php    
            $class="rider";
            if (!$rider->active)
            {
              $class .= " inactive";
            }
        ?>  
            <tr class="<?php echo $class;?>">  
              <td><?php echo ($i+1) . "."; ?></td>
              <td><?php echo $rider->number;?></td>
              <td><?php echo anchor('info/rider/'.$rider->rider_id,$rider->last_name." ".$rider->first_name);?></td>
              <td><?php echo lang($rider->type_description);?></td>
              <td><?php echo anchor('info/team/'.$rider->team_id, $rider->team_shortname);?></td>

                <?php
                $rider_stage_points = 0;
                $rider_yellow_points = 0;
                $rider_green_points = 0;
                $rider_mountain_points = 0;
                
                foreach(explode(',',$rider->points_stage) as $rider_points)
                {
                  $rider_stage_points = $rider_stage_points + $rider_points;
                  $total_stage_points = $total_stage_points + $rider_points;
                }
                foreach(explode(',',$rider->points_stage_yellow) as $rider_points)
                {
                  $rider_yellow_points = $rider_yellow_points + $rider_points;
                  $total_yellow_points = $total_yellow_points + $rider_points;
                }
                foreach(explode(',',$rider->points_stage_green) as $rider_points)
                {
                  $rider_green_points = $rider_green_points + $rider_points;
                  $total_green_points = $total_green_points +$rider_points;
                }
                foreach(explode(',',$rider->points_stage_mountain) as $rider_points)
                {
                  $rider_mountain_points = $rider_mountain_points + $rider_points;
                  $total_mountain_points = $total_mountain_points + $rider_points;
                }
                if($rider_stage_points>0)
                {
                  echo "<td class='centertext'>".$rider_stage_points."</td>";
                }
                else
                {
                  echo "<td class='centertext'> - </td>";
                }
                if($rider_yellow_points>0)
                {
                  echo "<td class='centertext'>".$rider_yellow_points."</td>";
                }
                else
                {
                  echo "<td class='centertext'> - </td>";
                }
                if($rider_green_points>0)
                {
                  echo "<td class='centertext'>".$rider_green_points."</td>";
                }
                else
                {
                  echo "<td class='centertext'> - </td>";
                }
                if($rider_mountain_points>0)
                {
                  echo "<td class='centertext'>".$rider_mountain_points."</td>";
                }
                else
                {
                  echo "<td class='centertext'> - </td>";
                }
                ?>

            </tr>

        <?php $i++; } ?>
        </tbody>
        <tfoot>
            <tr>
            <td colspan='4'></td>
            <td><?php echo lang('total');?></td>
            <td class='centertext'><?php echo $total_stage_points;?></td>
            <td class='centertext'><?php echo $total_yellow_points;?></td>
            <td class='centertext'><?php echo $total_green_points;?></td>
            <td class='centertext'><?php echo $total_mountain_points;?></td>
          </tr>
        </tfoot>
        </table>  
      </div>
    </div>


  </div>